function wpagebar(name) {
        this.name = name;
        this.page = 1;
        this.pageCount = 1;
        this.argName = 'page';
        this.showTimes = 1;
        this.perPageCount = 10;
        this.perCount = 10;
}

wpagebar.prototype.getPage = function(){
        var args = location.search;
        var reg = new RegExp('[\?&]?' + this.argName + '=([^&]*)[&$]?', 'gi');
        var chk = args.match(reg);
        this.page = RegExp.$1;
}
wpagebar.prototype.checkPages = function(){
        if (isNaN(parseInt(this.page))) this.page = 1;
        if (isNaN(parseInt(this.pageCount))) this.pageCount = 1;
        if (this.page < 1) this.page = 1;
        if (this.pageCount < 1) this.pageCount = 1;
        if (this.page > this.pageCount) this.page = this.pageCount;
        this.page = parseInt(this.page);
        this.pageCount = parseInt(this.pageCount);
}

wpagebar.prototype.createUrl = function (page) {
        if (isNaN(parseInt(page))) page = 1;
        if (page < 1) page = 1;
        if (page > this.pageCount) page = this.pageCount;
        var url = location.protocol + '//' + location.host + location.pathname;
        var args = location.search;
        var reg = new RegExp('([\?&]?)' + this.argName + '=[^&]*[&$]?', 'gi');
        args = args.replace(reg,'$1');
        if (args == '' || args == null) {
                args += '?' + this.argName + '=' + page;
        } else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
                        args += this.argName + '=' + page;
        } else {
                        args += '&' + this.argName + '=' + page;
        }
        return url + args;
}
wpagebar.prototype.toPage = function(page){
        var turnTo = 1;
        if (typeof(page) == 'object') {
                turnTo = page.options[page.selectedIndex].value;
        } else {
                turnTo = page;
        }
        //this.saveIdsToCooke();
        self.location.href = this.createUrl(turnTo);
}
wpagebar.prototype.saveIdsToCooke = function(){
	try{
		var ids=getSelectedCheckBoxValues('id');
		if(ids!=null && ids!=""){
			var cookieIds=getCookie("pageIdsSave");
			if(cookieIds !=null && cookieIds != "" && cookieIds != ","){
				ids=(cookieIds+","+ids).replace(/,+/g,",");
				setCookie("pageIdsSave",ids);
			}else{
				setCookie("pageIdsSave",ids);
			}
		}
	}catch(err){
	
	}
}
wpagebar.prototype.formatInputPage = function(e){ 
        var ie = navigator.appName=="Microsoft Internet Explorer"?true:false;
        if(!ie) var key = e.which;
        else var key = event.keyCode;
        if (key == 8 || key == 46 || (key >= 48 && key <= 57)) return true;
        return false;
}
wpagebar.prototype.createHtml = function(){
        var htmlString = '', prevPage, nextPage,startPage,endPage;        
        if(this.page <= 0)
        	this.page = 1;
        if(this.page > this.pageCount)
        	this.page = this.pageCount;
        prevPage = this.page - 1;
        nextPage = this.page + 1;
        startPage = this.page - 4;
        endPage = this.page + 5;
        
        if(startPage <= 0 ) {
        	startPage = 1;
        }
        
        if(endPage > this.pageCount) {
        	endPage = this.pageCount;
        }
        
        var cnt = endPage - startPage + 1;
        if(cnt < 10){
        	if(startPage > 1){
        		if(startPage - (10-cnt)>0)
        			startPage = startPage - (10-cnt);
        		else
        			startPage = 1;
        	}
        	else if(endPage < this.pageCount){
        		if(endPage + (10-cnt)<=this.pageCount)
        			endPage = endPage + (10-cnt);
        		else
        			endPage = this.pageCount;
        	}
        }

		htmlString += '';
        if(prevPage >= 1 ){
        	htmlString += '<a href="javascript:' + this.name + '.toPage(0);">首页</a> ';
			htmlString += '<a href="javascript:' + this.name + '.toPage(' + prevPage + ');">上一页</a> ';
        }
        /**
        if(startPage > 1){
        	htmlString += '<a href="javascript:' + this.name + '.toPage(1);">[1]</a> ';
        	htmlString += '... ';
        }
        for(var i = startPage; i <= endPage; i++){
            if (i == this.page) {
            	htmlString += '<span>' + i + '</span> ';
           	} else {
                htmlString += '<a href="javascript:' + this.name + '.toPage(' + i + ');">[' + i + ']</a> ';
        	}
        }
        **/
        if (nextPage <= this.pageCount) {
            htmlString += '<a href="javascript:' + this.name + '.toPage(' + nextPage + ');">下一页 </a>';
            htmlString += '<a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">最后一页</a>';
        }

		htmlString += ' ';
		if (this.pageCount < 1) {
			htmlString += '<input type="text" name="toPage" value="No Pages" class="pageText" disabled="disabled">';
			htmlString += '<input type="button" name="go" value="跳转" class="pagebutton" disabled="disabled">';
		}else{
			htmlString += '第<input type="text" id="pageInput' + this.showTimes + '" value="' + this.page + '" size="2" onKeyDown="if(event.keyCode==13) '+ this.name + '.toPage(this.value);" onkeypress="return ' + this.name + '.formatInputPage(event);" onfocus="this.select()">';
			htmlString += "/" + this.pageCount;
			htmlString += '页 <input type="button" name="go" value="跳转" class="button" onclick="' + this.name + '.toPage(document.getElementById(\'pageInput' + this.showTimes + '\').value);">';
		}
		htmlString += '';
		return htmlString;
}
wpagebar.prototype.createPageHtml = function(){
    var htmlString = '', prevPage, nextPage,startPage,endPage;        
    if(this.page <= 0)
    	this.page = 1;
    if(this.page > this.pageCount)
    	this.page = this.pageCount;
    prevPage = this.page - 1;
    nextPage = this.page + 1;
    startPage = this.page - 4;
    endPage = this.page + 5;
    
    if(startPage <= 0 ) {
    	startPage = 1;
    }
    
    if(endPage > this.pageCount) {
    	endPage = this.pageCount;
    }
    
    var cnt = endPage - startPage + 1;
    if(cnt < 10){
    	if(startPage > 1){
    		if(startPage - (10-cnt)>0)
    			startPage = startPage - (10-cnt);
    		else
    			startPage = 1;
    	}
    	else if(endPage < this.pageCount){
    		if(endPage + (10-cnt)<=this.pageCount)
    			endPage = endPage + (10-cnt);
    		else
    			endPage = this.pageCount;
    	}
    }

	htmlString += '<div class="page"><ul>';
    htmlString += '<li><a href="javascript:' + this.name + '.toPage(0);"><img src="images/leftBtn2.gif" alt="第一页" /></a></li>';
    htmlString += '<li><a href="javascript:' + this.name + '.toPage(' + prevPage + ');"><img src="images/leftBtn3.gif" alt="上一页" /></a></li>';        
    htmlString += '<li><a href="javascript:' + this.name + '.toPage(' + nextPage + ');"><img src="images/leftBtn4.gif" alt="下一页" /></a></li>';
    htmlString += '<li><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');"><img src="images/leftBtn5.gif" alt="最后一页" /></a></li>';        
    htmlString +='</ul></div>';
	return htmlString;
}
wpagebar.prototype.load = function(){
        this.getPage();
        this.checkPages();
        this.showTimes += 1;
        document.write(this.createHtml());
}
wpagebar.prototype.loadPage = function(){
    this.getPage();
    this.checkPages();
    this.showTimes += 1;
    document.write(this.createPageHtml());
}